//弹框中订单展示
import CommonTable from '@/components/CommonTable';
import { Image } from 'antd';
import { find } from 'lodash';

const GoodsListTable = (props) => {

	const { type, goodsList=[], data = [] } = props;

	const columns = [
		{
			title: '图片',
			dataIndex: 'ecGoodsImage',
			width: 120,
			render: (t, r) => <Image width={48} src={t || r.goodsImage} />
		},
		{
			title: '平台商品名称',
			dataIndex: 'ecGoodsName',
			width: 200,
			render: (t, r) => t || r.goodsName
		},
		{
			title: '平台商品编码',
			dataIndex: 'ecSkuId',
			width: 120,
			// render: (t, r) => t || r.skuId
			render: (t, r) => t

		},
		{
			title: '颜色规格',
			dataIndex: 'ecGoodsSpec',
			width: 120,
			render: (t, r) => t || r.goodsSpec
		},
		{
			title: '款式编码',
			dataIndex: 'ecSpuId',
			width: 100,
			render: (t, r) => t || r.spuId
		},
		{
			title: '商品单价',
			dataIndex: 'ecGoodsPrice',
			width: 120,
			render: (t, r) => {
				let val;
				if(type == 'aftersales') {
					if(r.ecGoodsPrice || r.ecGoodsPrice == 0) {
						val = r.ecGoodsPrice;
					} else {
						if(r.outGoodsSn) {
							const obj = find(goodsList, ['outGoodsSn', r.outGoodsSn]);
							if(obj) {
								val = (obj.ecGoodsPrice || obj.ecGoodsPrice == 0) ? obj.ecGoodsPrice : obj.goodsPrice;
							}
						}
					}
				} else {
					val = (t || t == 0) ?  t : r.goodsPrice;
				}
				return (val || val == 0) ? <span style={{color: '#F03D29'}}>￥{val}</span> : null
			}
		},
		{
			title: '申请退货数量',
			dataIndex: 'goodsNum',
			width: 120,
		},
	];

	const columns1 = [
		{
			title: '实际拆包数量',
			dataIndex: 'unpackNum',
			width: 120,
		},
		{
			title: '次品数量',
			dataIndex: 'unpackDefectiveNum',
			width: 120,
		},
		{
			title: '退款金额',
			dataIndex: 'refundAmount',
			width: 120,
		},
		{
			title: '商品唯一码',
			dataIndex: 'unpackUniqueCodes',
			width: 120,
			render: t => {
				return (
					t.map(v => (
						<div key={v}>{v}</div>
					))
				)
			}
		},
	];

	if(type == 'orderGoods') {
		columns.push(...columns1);
	}

	const TableProps = {
		rowKey: 'id',
		data,
		columns,
	}

	return (
		<CommonTable style={{ marginBottom: '16px' }} {...TableProps} />
	)
}

export default GoodsListTable;